From 70625ce62aba43e586901d340ae81c2830d9fbc6 Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Thu, 26 Dec 2024 23:41:15 +0100 Subject: init --- src/pages/blog/[event]/[...slug].astro | 50 +++++++++++++ src/pages/blog/[event]/index.astro | 126 +++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 src/pages/blog/[event]/[...slug].astro create mode 100644 src/pages/blog/[event]/index.astro (limited to 'src/pages/blog/[event]') diff --git a/src/pages/blog/[event]/[...slug].astro b/src/pages/blog/[event]/[...slug].astro new file mode 100644 index 0000000..2d7c495 --- /dev/null +++ b/src/pages/blog/[event]/[...slug].astro @@ -0,0 +1,50 @@ +--- +import { type CollectionEntry, getCollection } from "astro:content"; +import BlogPost from "../../../layouts/BlogPost.astro"; +import { render } from "astro:content"; +import { object } from "astro:schema"; + +export async function getStaticPaths() { + const posts = await getCollection("blog"); + const events = Object.keys( + Object.groupBy( + posts.map((post) => ({ + id: post.id, + event: post.id.split("/").at(-2) || "", + })), + (post) => post.event + ) + ).filter((event) => event); + + const postPaths = posts.map((post) => post.id.split("/").at(-1)); + console.log(postPaths); + + const paths = []; + for (const event of events) { + for (const post of postPaths) { + paths.push({ + params: { event, slug: post }, + props: { post: posts.find((p) => p.id.endsWith(post!!)) }, + }); + } + } + + return paths; + // return posts.map((post) => ({ + // params: { slug: post.id, event: post.id.split("/").at(-2) }, + // props: { post }, + // })); +} +// type Props = { +// post: CollectionEntry<"blog">; +// siblings: CollectionEntry<"blog">[]; +// }; +type Props = CollectionEntry<"blog">; + +const post = Astro.props; +const { Content } = await render(post.post); +--- + + + + diff --git a/src/pages/blog/[event]/index.astro b/src/pages/blog/[event]/index.astro new file mode 100644 index 0000000..5bab8f0 --- /dev/null +++ b/src/pages/blog/[event]/index.astro @@ -0,0 +1,126 @@ +--- +import BaseHead from "../../../components/BaseHead.astro"; +import Header from "../../../components/Header.astro"; +import Footer from "../../../components/Footer.astro"; +import { SITE_TITLE, SITE_DESCRIPTION } from "../../../consts"; +import { getCollection } from "astro:content"; +import FormattedDate from "../../../components/FormattedDate.astro"; + +export async function getStaticPaths() { + const blogs = await getCollection("blog"); + const events = Object.keys( + Object.groupBy( + blogs.map((b) => ({ + id: b.id, + event: b.id.split("/").at(-2) || "", + })), + (b) => b.event + ) + ); + console.log(events); + return events.filter((e) => e).map((event) => ({ params: { event } })); +} + +const event = Astro.params.event; + +const blogs = await getCollection("blog"); + +const posts = blogs + .filter((b) => b.id.includes(event + "/")) + .sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()); +--- + + + + + + + + +
+
+
+ +
+
+